//
//  MineCollectCell.m
//  quxiangtao
//
//  Created by HHuajiang on 2018/12/24.
//  Copyright © 2018 shanhaijin. All rights reserved.
//

#import "MineCollectCell.h"

@implementation MineCollectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
        self.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
        
        UIImageView *bgimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"collect_juxing8"]];
        [self.contentView addSubview:bgimage];
        [bgimage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_equalTo(0);
        }];
        
        UIImageView *shopImage = [[UIImageView alloc] init];
        shopImage.backgroundColor = Colordddddd;
        [bgimage addSubview:shopImage];
        [shopImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Margin+jisuan(10));
            make.size.mas_equalTo(CGSizeMake(jisuan(160), jisuan(160)));
            make.centerY.equalTo(bgimage.mas_centerY);
        }];
        [shopImage sd_setImageWithURL:[NSURL URLWithString:@"http://img5.duitang.com/uploads/item/201208/23/20120823175210_HnQJc.jpeg"]];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"分公司广东发改局12394234发的所";
        titleLabel.numberOfLines = 2;
        titleLabel.font = Font(30);
        titleLabel.textColor = Color333333;
        [bgimage addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(shopImage.mas_right).offset(Margin);
            make.top.equalTo(shopImage.mas_top).offset(2);
            make.right.mas_equalTo(-Margin);
        }];
        
        UILabel *pricelabel = [[UILabel alloc] init];
        pricelabel.textColor = Colorff0000;
        pricelabel.text = @"￥110800.00";
        NSMutableAttributedString *priceAttributeStr = [[NSMutableAttributedString alloc] initWithString:pricelabel.text];
        [priceAttributeStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
        [priceAttributeStr addAttribute:NSFontAttributeName value:Font(30) range:NSMakeRange(1, pricelabel.text.length - 1)];
        [bgimage addSubview:pricelabel];
        [pricelabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel.mas_left);
            make.top.equalTo(titleLabel.mas_bottom).offset(jisuan(12));
        }];
        pricelabel.attributedText = priceAttributeStr;
        
        UILabel *contrastLabel = [[UILabel alloc] init];
        contrastLabel.text = @"比收藏时降价0元";
        contrastLabel.font = Font(20);
        contrastLabel.textColor = Color999999;
        [bgimage addSubview:contrastLabel];
        [contrastLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(pricelabel.mas_left);
            make.bottom.equalTo(shopImage.mas_bottom).offset(-2);
        }];
        
        UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [buyButton setBackgroundImage:[UIImage imageNamed:@"collect_select25"] forState:UIControlStateNormal];
        buyButton.titleLabel.font = Font(30);
        [buyButton setTitle:@"购买" forState:UIControlStateNormal];
        [bgimage addSubview:buyButton];
        [buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(contrastLabel.mas_bottom);
            make.right.mas_equalTo(-jisuan(40));
            make.size.mas_equalTo(CGSizeMake(jisuan(150), jisuan(60)));
        }];
        
    }
    return self;
}

-(void)layoutSubviews{
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *view in control.subviews){
                if ([view isKindOfClass: [UIImageView class]]) {
                    UIImageView *image=(UIImageView *)view;
                    if (self.selected) {
                        image.image=[UIImage imageNamed:@"collect_selecta"];
                    }else{
                        image.image=[UIImage imageNamed:@"collect_wei"];
                    }
                }
            }
        }
    }
    [super layoutSubviews];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    for (UIControl *control in self.subviews){
        if ([control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
            for (UIView *view in control.subviews){
                if ([view isKindOfClass: [UIImageView class]]) {
                    UIImageView *image=(UIImageView *)view;
                    if (!self.selected) {
                        image.image=[UIImage imageNamed:@"collect_selecta"];
                    }else{
                        image.image=[UIImage imageNamed:@"collect_wei"];
                    }
                }
            }
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.backgroundColor = WhiteColor;
}

@end
